package com.example.module.custom.adapter;

import android.animation.Animator;
import android.content.Context;
import android.graphics.Color;
import android.text.Html;
import android.util.Log;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.TextView;

import com.chad.library.adapter.base.animation.ScaleInAnimation;
import com.example.module.custom.R;
import com.example.module.custom.R2;
import com.example.module.custom.bean.PQCListBean;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @name BlockDemo
 * @class name：com.nand.module.function.adapter
 * @classdescribe  pqc列表页面
 * @anthor ljp
 * @time 2020/1/6 16:09
 */
public class PQCListAdapter extends BaseAdapter<PQCListBean.DataListBean> {
    private String TAG = "PQCListAdapter";
    private List<PQCListBean.DataListBean> dataListBeanList;
    private int flag;
    private ScaleInAnimation mSelectAnimation = new ScaleInAnimation();
    public PQCListAdapter(Context mContext,
                          ArrayList<PQCListBean.DataListBean> mData, int resId,int flag) {
        super(mContext, mData, resId);
        dataListBeanList = new ArrayList<>();
        this.dataListBeanList = tlist;
        this.flag = flag;
        //new ViewHolder(View.inflate(mContext,resId,null));
    }

    public List<PQCListBean.DataListBean> getDataListBeanList() {
        return dataListBeanList;
    }

    @Override
    protected RecyclerView.ViewHolder getHeaderViewHolder(View view) {
        return null;
    }

    @Override
    protected RecyclerView.ViewHolder getItemViewHolder(View view) {
        return new ViewHolder(view);
    }

    @Override
    protected RecyclerView.ViewHolder getFooterViewHolder(View view) {
        return null;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        Log.i(TAG, "onBindViewHolder: ------"+dataListBeanList.size());
        if(holder instanceof ViewHolder){
            PQCListBean.DataListBean pqcListBean = tlist.get(position);
            ((ViewHolder) holder).tvPqc.setText(pqcListBean.getCheckID());
            ((ViewHolder) holder).tvPqcNum.setText(pqcListBean.getProductionStageName());
            ((ViewHolder) holder).tvPqcName.setText(pqcListBean.getProcessContent());
            ((ViewHolder) holder).tvPqcWork.setText(pqcListBean.getPartId());
            ((ViewHolder) holder).tvPqcId.setText(pqcListBean.getPartName());
            ((ViewHolder) holder).tvPqcCode.setText(pqcListBean.getWipBatch());
            ((ViewHolder) holder).tvPqcPerson.setText(pqcListBean.getUserName());
            ((ViewHolder) holder).tvPqcDate.setText(Html.fromHtml("创建时间：&#12288;<font color='#333333'>"+pqcListBean.getCreatedTime()+"</font>"));
            if(flag == 1){
                if(pqcListBean.getReviewResult() == 2) {
                    if (pqcListBean.getCheckResult() == 0) {
                        //检查结果 0合格1不合格
                        ((ViewHolder) holder).tvIs.setText("合格");
                        ((ViewHolder) holder).tvIs.setTextColor(Color.parseColor(context.getString(R.color.color_08664B)));
                    } else {
                        ((ViewHolder) holder).tvIs.setText("不合格");
                        ((ViewHolder) holder).tvIs.setTextColor(Color.RED);
                    }
                }else {
                    if (pqcListBean.getReviewResult() == 0) {
                        //检查结果 0合格1不合格
                        ((ViewHolder) holder).tvIs.setText("合格");
                        ((ViewHolder) holder).tvIs.setTextColor(Color.parseColor(context.getString(R.color.color_08664B)));
                    } else {
                        ((ViewHolder) holder).tvIs.setText("不合格");
                        ((ViewHolder) holder).tvIs.setTextColor(Color.RED);
                    }
                    }
            }else {
                if(pqcListBean.getReviewResult() == 0){
                    //检查结果 0合格1不合格
                    ((ViewHolder) holder).tvIs.setText("合格");
                    ((ViewHolder) holder).tvIs.setTextColor(Color.parseColor(context.getString(R.color.color_08664B)));
                }else {
                    ((ViewHolder) holder).tvIs.setText("不合格");
                    ((ViewHolder) holder).tvIs.setTextColor(Color.RED);
                }
            }

            ((ViewHolder) holder).view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    onItemClickListener.OnItemClick(position,view);
                }
            });
           // ((ViewHolder) holder).tvIs.setText(pqcListBean.isQual());
        }
    }

    @Override
    public void onViewAttachedToWindow(@NonNull RecyclerView.ViewHolder holder) {

            super.onViewAttachedToWindow(holder);
            addAnimation((ViewHolder)holder);
    }

    private void addAnimation(ViewHolder holder) {
        for (Animator anim : mSelectAnimation.getAnimators(holder.itemView)) {
            anim.setDuration(300).start();
            anim.setInterpolator(new LinearInterpolator());
        }
    }
    class ViewHolder extends BaseViewHolder{
        @BindView(R2.id.tv_pqc)
        TextView tvPqc;
        @BindView(R2.id.tv_is)
        TextView tvIs;
        @BindView(R2.id.tv_pqc_num)
        TextView tvPqcNum;
        @BindView(R2.id.tv_pqc_name)
        TextView tvPqcName;
       /* @BindView(R2.id.tv_pqc_line)
        TextView tvPqcLine;*/
        @BindView(R2.id.tv_pqc_work)
        TextView tvPqcWork;
        @BindView(R2.id.tv_pqc_id)
        TextView tvPqcId;
        @BindView(R2.id.tv_pqc_person)
        TextView tvPqcPerson;
        @BindView(R2.id.tv_pqc_work_code)
        TextView tvPqcCode;
        @BindView(R2.id.tv_pqc_date)
        TextView tvPqcDate;
        View view;
        public ViewHolder(View itemView) {
            super(itemView);
            view = itemView;
            ButterKnife.bind(this,itemView);

        }
    }
}
